package com.zjitc.controller;

import com.zjitc.pojo.Category;
import com.zjitc.pojo.Product;
import com.zjitc.service.CategoryService;
import com.zjitc.service.ProductService;
import com.zjitc.vo.product.Prestrain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Create By IntelliJ IDEA
 *
 * @author: myq
 * @create-Time: 2017/11/11  16:33
 */
@Controller
public class IndexController {

  @Autowired
  private ProductService service;
  @Autowired
  private CategoryService categoryService;

  @RequestMapping("/index")
  public ModelAndView index() {
    List<Product> hots = service.findHots();
    List<Product> news = service.findNews();


    //预加载商品
    List<Prestrain> prestrains = service.prestrainProduct();
    ModelAndView mv = new ModelAndView("index");
    mv.addObject("prePro",prestrains);
    mv.addObject("hots", hots);
    mv.addObject("news", news);
    return mv;
  }


  @RequestMapping("/getCategory")
  @ResponseBody
  public Object getCategory(){
    List<Category> categories = categoryService.adminfindAll();
    return categories;
  }

  @RequestMapping("/gotoaddress")
  public ModelAndView gotoaddress(String address) {
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName(address);
    return modelAndView;
  }

  @RequestMapping("/gotoContactUs")
  public String gotoContactUs(){
    return "contactUs";
  }

  @RequestMapping("/gotoMap")
  public String gotoMap(){
    return "map";
  }

  @RequestMapping("/gotoAboutUs")
  public String gotoAboutUs(){
    return "aboutUs";
  }
}
